package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Reply;
import cn.wolfcode.trip.base.domain.Review;
import cn.wolfcode.trip.base.mapper.ReplyMapper;
import cn.wolfcode.trip.base.mapper.ReviewMapper;
import cn.wolfcode.trip.base.service.IReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ReplyServiceImpl implements IReplyService {

    @Autowired
    private ReplyMapper replyMapper;
    @Autowired
    private ReviewMapper reviewMapper;
    @Override
    public void save(String contentDetail, Long fromUserId,Long replyId, Long commentId) {
        Reply reply = new Reply();
        reply.setCommentId(commentId);
        reply.setContentDetail(contentDetail);
        reply.setFromUserId(fromUserId);
        reply.setCreatTime(new Date());
        reply.setReplyId(replyId);
        //取出一级评论的id,取出发表评论的用户id
        Review review = reviewMapper.selectByReplyId(replyId);
        reply.setToUserId(review.getUserId());
        replyMapper.insert(reply);
    }

    @Override
    public List<Reply> getReplysByCommentId(Long commentId) {

        List<Reply> list= replyMapper.getReplysByCommentId(commentId);
        return list;
    }
}
